<!DOCTYPE html>
<html>

	<head>

		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">

		<title>后台 - 添加代理</title>
		<meta name="keywords" content="">
		<meta name="description" content="">

		<link rel="shortcut icon" href="favicon.ico">
		<link href="__PUBLIC__/Admin/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
		<link href="__PUBLIC__/Admin/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
		<link href="__PUBLIC__/Admin/css/plugins/iCheck/custom.css" rel="stylesheet">
		<link href="__PUBLIC__/Admin/css/animate.min.css" rel="stylesheet">
		<link href="__PUBLIC__/Admin/css/style.min862f.css?v=4.1.0" rel="stylesheet">

	</head>

	<body class="gray-bg">
		<div class="wrapper wrapper-content animated fadeInRight">
			<div class="row">
				<div class="col-sm-12">
					<div class="ibox float-e-margins">
						<div class="ibox-title">						
							<div class="ibox-tools">
								<a class="collapse-link">
									<i class="fa fa-chevron-up"></i>
								</a>
							</div>
						</div>
						<div class="ibox-content">
							<form class="form-horizontal" method="post" action="{:U('Admin/Admin/addagent')}" name="signupForm" id="signupForm" enctype="multipart/form-data">
							<input type="hidden" name="id" value="{$info.id}" />
								
								<if condition="$Think.session.admin.role_id eq 0">
									<div class="form-group">
										<label class="col-sm-2 control-label">代理级别</label>
										<div class="col-sm-6">
											<select onchange="rank(this[selectedIndex].value)" name="agent_rank" class="form-control m-b">
												<option value="1">一级代理</option>
												<option value="2">二级代理</option>
											</select>
										</div>
									</div>
									<div class="form-group" style="display: none;" id="up">
										<label class="col-sm-2 control-label">上级代理</label>
										<div class="col-sm-6">
											<select name="agent_up" class="form-control m-b ">
												<option value="0">选择上级代理</option>
												<volist name="agent_list" id="vo">
													<option value="{$vo.id}">{$vo.username}</option>
												</volist>
											</select>
										</div>
									</div>
									<div class="hr-line-dashed"></div>
								</if>
								
								<div class="form-group">
									<label class="col-sm-2 control-label">账号</label>
									<div class="col-sm-6">
										<input type="text" name="username" id="username"  placeholder="输入用户名" class="form-control">
									</div>
								</div>
								<div class="hr-line-dashed"></div>
								<div class="form-group">
									<label class="col-sm-2 control-label">密码</label>
									<div class="col-sm-6">
										<input type="text" name="password" id="password"  placeholder="输入密码" class="form-control">
									</div>
								</div>
								<div class="hr-line-dashed"></div>
								<div class="form-group">
									<label class="col-sm-2 control-label">代理名称</label>
									<div class="col-sm-6">
										<input type="text" name="nickname" id="nickname"  placeholder="输入用户名" class="form-control">
									</div>
								</div>
								<div class="hr-line-dashed"></div>
								<if condition="$Think.session.admin.role_id eq 0">
									<div class="form-group">
										<label class="col-sm-2 control-label">角色</label>
										<div class="col-sm-6">
											<select name = "role_id" class="form-control m-b ">
												<foreach name="rolelist " item="vo">
													<option value="{$vo.id}" <eq name="vo.id" value="$info.role_id">selected</eq> >{$vo.role_name}</option>
												</foreach>
											</select>
										</div>
									</div>
									<div class="hr-line-dashed"></div>
								</if>
								
								<div class="form-group">
									<div class="col-sm-4 col-sm-offset-2">
										<button class="btn btn-primary" type="submit">保存内容</button>
										<a class="btn btn-danger" href="{:U('Admin/Admin/agentlist')}">取消</a>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<script src="__PUBLIC__/Admin/js/jquery.min.js?v=2.1.4"></script>
		<script src="__PUBLIC__/Admin/js/bootstrap.min.js?v=3.3.6"></script>
		<script src="__PUBLIC__/Admin/js/content.min.js?v=1.0.0"></script>
		<script src="__PUBLIC__/Common/js/ajaxForm.js"></script>
		<script src="__PUBLIC__/Common/layer/layer.js"></script>
		<script>
			function rank(a){
				if(a==2){
					$('#up').css('display','block');
				}else{
					$('#up').css('display','none');
				}
			}
			$(function(){
				$('#signupForm').ajaxForm({
					beforeSubmit: checkForm,
					success: complete, 
					dataType: 'json'
				});
				function checkForm(){
					if( '' == $.trim($('#username').val())){
						layer.alert('用户名', {icon: 5}, function(index){
							layer.close(index);
							$('#username').focus();
						});
						return false;
					}
					if( '' == $.trim($('#password').val())){
						layer.alert('密码', {icon: 5}, function(index){
							layer.close(index);
							$('#password').focus();
						});
						return false;
					}
				}
				function complete(data){
					if(data.status==1){
						$('.btn-primary').attr('disabled','disabled');
						layer.msg(data.info, function(index){
			 				layer.close(index);
							window.location.href=data.url;
						});
					}else{
						layer.msg(data.info);
						return false;	
					}
				}
			});
		</script>
		<script>
			function backpic(picurl){
				$("#img0").attr("src",picurl);
				$("input[name='file0']").val("");
				$("input[name='oldcheckpic']").val(picurl);
			}
			$("#file0").change(function(){
				var objUrl = getObjectURL(this.files[0]) ;
				console.log("objUrl = "+objUrl) ;
				if (objUrl) {
					$("#img0").attr("src", objUrl) ;
				}
			}) ;
	
			function getObjectURL(file) {
				var url = null ;
				if (window.createObjectURL!=undefined) {
					$("#oldcheckpic").val("nopic");
					url = window.createObjectURL(file) ;
				} else if (window.URL!=undefined) {
					$("#oldcheckpic").val("nopic");
					url = window.URL.createObjectURL(file) ;
				} else if (window.webkitURL!=undefined) {
					$("#oldcheckpic").val("nopic");
					url = window.webkitURL.createObjectURL(file) ;
				}
				return url ;
			}
		</script>
	</body>

</html>